using OpenTK.Graphics.OpenGL;
using OpenTK.Mathematics;

namespace AssetImporter
{
    static public class Importer
    {
        #pragma warning disable CS8618
        public static MainWindow window { get; private set; }
        public static IUI ui { get; private set; }
        public static IRender render { get; private set; }
        public static IOrderManager orderManager { get; private set; }
        #pragma warning restore CS8618

        const int WINDOW_WIDTH = 800;
        const int WINDOW_HEIGHT = 600;
        public static void InitAndRun()
        {
            init();
            window.Run();
        }

        static void init()
        {
            var inputHandle = new InputHandle();
            window = new MainWindow(WINDOW_WIDTH, WINDOW_HEIGHT, loop, inputHandle);
            window.OnWindowReset += (int w, int h) => { GL.Viewport(0, 0, w, h); };
            ui = new UI(WINDOW_WIDTH, WINDOW_HEIGHT, inputHandle);
            render = new WorldRender(WINDOW_WIDTH, WINDOW_HEIGHT);
            orderManager = new OrderManager();
        }

        static void loop(double time)
        {
            orderManager.DoAll();
            GL.ClearColor(new Color4(56, 84, 84, 255));
            GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit | ClearBufferMask.StencilBufferBit);

            render.Logic(time);
            render.Render();

            ui.Logic(time);
            ui.Render();
            window.SwapBuffers();
        }
    }

    class QuitOrder : IOrder
    {
        public QuitOrder(){}
        public void Do(){ Importer.window.Close(); }
    }
}